package com.hxd.otc.module.my.model;

import com.hxd.otc.api.IBondApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.common.enums.RoleTypeEnum;
import com.hxd.otc.module.my.bean.YsPreBean;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.uber.autodispose.AutoDisposeConverter;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by lzy on 2018/10/8 0008.
 * description ${保证金model}
 */
public class BondModel {

    private BondModel() {
    }

    private static class SingletonHolder {
        private static final BondModel instance = new BondModel();
    }

    public static BondModel getInstance() {
        return BondModel.SingletonHolder.instance;
    }


    /**
     * 获取申请广告商的状态和保证金信息
     */
    public void requestYsApplyPreInfo(BaseObserver<YsPreBean> observer, AutoDisposeConverter<BaseBean<YsPreBean>> converter) {
        getBondApi().getYsPreApply()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 获取申请广告商的保证金信息
     */
    public void requestYsBond(BaseObserver<YsPreBean> observer, AutoDisposeConverter<BaseBean<YsPreBean>> converter) {
        getBondApi().getYsBond()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 广告商申请
     * @param symbol    保证金币种
     * @param idcardFrontUrl    身份证正面图
     * @param idcardBackUrl     身份证背面图
     * @param idcardCertUrl     手持广告商认证图
     * @param sliverType     广告商类型,0普通广告商，1无感支付广告商
     */
    public void apply(String symbol, String idcardFrontUrl, String idcardBackUrl, String idcardCertUrl,
                      RoleTypeEnum sliverType, BaseObserver<Object> observer, AutoDisposeConverter<BaseBean<Object>> converter) {
        getBondApi().ysApply(symbol, idcardFrontUrl, idcardBackUrl, idcardCertUrl, sliverType.getValue())
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    private IBondApi getBondApi() {
        return RetrofitManager.getDefault().create(IBondApi.class);
    }
}
